/********************************************************************************************/
/*																							*/
/*								Twn_ReportBuilder.cpp										*/
/*																							*/
/*	Builds all kind of reports required by Tianwan NPP FHM CCS applications.				*/
/*																							*/
/*	Author:		Matteo Tavella																*/
/*	Date:		02/05/2002																	*/
/*																							*/
/********************************************************************************************/

#define ALONE_TWNREPBUILDER
#include "Twn_ReportBuilder.h"

TCHAR	templatePSASPath[PATH_LEN + 1];
TCHAR	templateRPPath[PATH_LEN + 1];
TCHAR	templateFALVPath[PATH_LEN + 1];
TCHAR	templateDMPPath[PATH_LEN + 1];
TCHAR	templateMOVPath[PATH_LEN + 1];
TCHAR	templateFAPath[PATH_LEN + 1];
TCHAR	defaultFileNamePSAS[FILE_NAME_LEN + 1];
TCHAR	defaultFileNameRP[FILE_NAME_LEN + 1];
TCHAR	defaultFileNameFALV[FILE_NAME_LEN + 1];
TCHAR	defaultFileNameDMP[FILE_NAME_LEN + 1];
TCHAR	defaultFileNameMOV[FILE_NAME_LEN + 1];
TCHAR	defaultFileNameFA[FILE_NAME_LEN + 1];

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved ){
	LONG		res;
	LPDWORD		type;
	LPBYTE		data;
	LPDWORD		size;
	HKEY		hKey;
	DWORD		dwBufLen = PATH_LEN;
    
	size = 0;
	data = 0;
	type = 0;
	
	//Prelevo dal registro il path di default del template per i report PSAS.//
	RegOpenKeyEx(HKEY_LOCAL_MACHINE, 
				 TEXT("SOFTWARE\\ABB\\Power Generation Portal\\Tianwan\\VolDia"),
				 0,
				 KEY_QUERY_VALUE,
				 &hKey);
	
	res = RegQueryValueEx(hKey,
						  TEXT("TemplatePSASPath"),
						  NULL,
						  NULL,
						  (LPBYTE)templatePSASPath,
						  &dwBufLen);
	if(res != ERROR_SUCCESS)
		return FALSE;

	//Prelevo dal registro il path di default per i report PSAS.//
	dwBufLen = PATH_LEN;
	res = RegQueryValueEx(hKey,
						  TEXT("NamePSASFile"),
						  NULL,
						  NULL,
						  (LPBYTE)defaultFileNamePSAS,
						  &dwBufLen);
	
	if(res != ERROR_SUCCESS)
		return FALSE;

	//Prelevo dal registro il path di default per i report RP//
	dwBufLen = PATH_LEN;
	res = RegQueryValueEx(hKey,
						  TEXT("NameRPFile"),
						  NULL,
						  NULL,
						  (LPBYTE)defaultFileNameRP,
						  &dwBufLen);
	if(res != ERROR_SUCCESS)
		return FALSE;

	//Prelevo dal registro il path del documento default per i report RP//
	dwBufLen = PATH_LEN;
	res = RegQueryValueEx(hKey,
						  TEXT("TemplateRPPath"),
						  NULL,
						  NULL,
						  (LPBYTE)templateRPPath,
						  &dwBufLen);
	if(res != ERROR_SUCCESS)
		return FALSE;
	
	//Prelevo dal registro il path di default per il report FALV//
	dwBufLen = PATH_LEN;
	res = RegQueryValueEx(hKey,
						  TEXT("NameFALVFile"),
						  NULL,
						  NULL,
						  (LPBYTE)defaultFileNameFALV,
						  &dwBufLen);
	if(res != ERROR_SUCCESS)
		return FALSE;

	//Prelevo dal registro il path del documento default per il report FALV//
	dwBufLen = PATH_LEN;
	res = RegQueryValueEx(hKey,
						  TEXT("TemplateFALVPath"),
						  NULL,
						  NULL,
						  (LPBYTE)templateFALVPath,
						  &dwBufLen);
	if(res != ERROR_SUCCESS)
		return FALSE;

	//Prelevo dal registro il path di default per il report DMP//
	dwBufLen = PATH_LEN;
	res = RegQueryValueEx(hKey,
						  TEXT("NameDMPFile"),
						  NULL,
						  NULL,
						  (LPBYTE)defaultFileNameDMP,
						  &dwBufLen);
	if(res != ERROR_SUCCESS)
		return FALSE;

	//Prelevo dal registro il path del documento default per il report DMP//
	dwBufLen = PATH_LEN;
	res = RegQueryValueEx(hKey,
						  TEXT("TemplateDMPPath"),
						  NULL,
						  NULL,
						  (LPBYTE)templateDMPPath,
						  &dwBufLen);
	if(res != ERROR_SUCCESS)
		return FALSE;

	//Prelevo dal registro il path di default per il report dei movimenti//
	dwBufLen = PATH_LEN;
	res = RegQueryValueEx(hKey,
						  TEXT("NameMOVFile"),
						  NULL,
						  NULL,
						  (LPBYTE)defaultFileNameMOV,
						  &dwBufLen);
	if(res != ERROR_SUCCESS)
		return FALSE;

	//Prelevo dal registro il path del documento default per il report dei movimenti//
	dwBufLen = PATH_LEN;
	res = RegQueryValueEx(hKey,
						  TEXT("TemplateMOVPath"),
						  NULL,
						  NULL,
						  (LPBYTE)templateMOVPath,
						  &dwBufLen);
	if(res != ERROR_SUCCESS)
		return FALSE;

	//Prelevo dal registro il path di default per il report dei movimenti//
	dwBufLen = PATH_LEN;
	res = RegQueryValueEx(hKey,
						  TEXT("NameFAFile"),
						  NULL,
						  NULL,
						  (LPBYTE)defaultFileNameFA,
						  &dwBufLen);
	if(res != ERROR_SUCCESS)
		return FALSE;

	//Prelevo dal registro il path del documento default per il report dei movimenti//
	dwBufLen = PATH_LEN;
	res = RegQueryValueEx(hKey,
						  TEXT("templateFAPath"),
						  NULL,
						  NULL,
						  (LPBYTE)templateFAPath,
						  &dwBufLen);
	if(res != ERROR_SUCCESS)
		return FALSE;

	res = RegCloseKey(hKey);
	if(res != ERROR_SUCCESS)
		return FALSE;
    return TRUE;  // Successful DLL_PROCESS_ATTACH.
}

/********************************************************************************************/
/*																							*/
/*	Function:		BuildReport																*/
/*																							*/
/*	Description:	Builds all kind of record reqired by Tianwan Applications				*/
/*																							*/
/*	Input:			reportType		-	Type of record to build								*/
/*										1)	REP_PSAS_FA										*/
/*										2)	REP_PSAS_HECA									*/
/*										3)	REP_PSAS_REACT									*/
/*										4)	REP_RP_LOAD										*/
/*										5)	REP_RP_UNLOAD									*/
/*										6)	REP_RP_SFP										*/
/*										7)	REP_RP_REACT									*/
/*										8)	REP_MOV											*/
/*										9)	REP_FA_HIST										*/
/*										10)	REP_FALV										*/
/*										11)	REP_DMP											*/
/*					userName		-	Name of the user who builds report					*/
/*					xlsObj			-	Excel object										*/
/*																							*/
/*	Output:			----------																*/
/*																							*/
/*	Return:			RETSTAT			-	RT_NORMAL		Succesful report creation			*/
/*										RT_FAILED		Erorrs occurred						*/
/*																							*/
/********************************************************************************************/
RETSTAT BuildReport(int reportType, TCHAR userName[SZUNAM+1]){
	RETCOND		retCnd;
	RETSTAT		retSt;
	BOOL		retB;
	FILEIDX		filePhas;
	FILEIDX		fileCamp;
	FILEIDX		fileCell;
	GENIDX		zoneHeca1Idx;
	GENIDX		zoneHeca2Idx;
	GENIDX		zoneFA1Idx;
	GENIDX		zoneFA2Idx;
	GENIDX		zoneFA3Idx;
	GENIDX		zoneFA4Idx;
	GENIDX		zoneFA5Idx;
	GENIDX		zoneFA6Idx;
	GENIDX		zoneFA7Idx;
	GENIDX		zoneFA8Idx;
	GENIDX		zoneFA9Idx;
	GENIDX		zoneFA10Idx;
	GENIDX		zoneFAIdx;
	GENIDX		zoneHecaIdx;
	GENIDX		zoneReactIdx;
	GENIDX		zoneIOIdx;
	GENIDX		zoneFFDSIdx;
	GENIDX		startZoneIdx;
	GENIDX		destZoneIdx;
	GENIDX		sfpIdx;
	GENIDX		N_FAIdx;
	GENIDX		S_FAIdx;
	GENIDX		D_FAIdx;
	GENIDX		N_CLIdx;
	GENIDX		S_CLIdx;
	GENIDX		HECAIdx;
	GENIDX		CLFRMIdx;
	GENIDX		objIdx;
	GENIDX		objtIdx;
	GENIDX		genIdx;
	GENIDX		FAGRLIdx;
	GENIDX		displIdx;
	OBJNAME		objName;
	OBJTNAME	objtName;
	OBJNAME		objName_1;
	OBJTNAME	objtName_1;
	DWORD		year, month, day, hour, min, sec, msec;
	EXTIME		time;
	SYSTEMTIME	sysTime;
	TECCYCID	tcId;
	TECCYCDESCR	tcDescr;
	MIC_CMDDESC	micrDescr;
	CXlsObj		*excelObj;
	phas_struc	phas;
	t_camp		camp;
	t_falv		falv;
	t_dmp		dmp;
	t_cell		cell;
	t_rpmb		rpmb;
//	t_sippRes	sipp;
	TCHAR		temp[256], temp_2[256], temp_3[256];
	TCHAR		phUserName[SZUNAM+1];
	TCHAR		echoMsg[256];
	TCHAR		fileName[256];
	int			retI;
	int			i, j;
	int			totNum;
	int			fullNum;
	int			newFAClus;
	int			newFA;
	int			newClus;
	int			spentClus;
	int			spentFA;
	int			spentFAClus;
	int			clusFrm;
	int			clusFrmClus;
	int			Heca;
	int			HecaFA;
	int			NFA_1_21;
	int			NFA_1_3;
	int			NCL_1_21;
	int			NCL_1_3;
	int			HECA_1_22;
	int			SFA_21_1;
	int			SCL_21_1;
	int			CLFRM_21_1;
	int			HECA_DFA_22_1;
	int			SFA_21_21;
	int			SFA_23_21;
	int			DFA_23_22;
	int			NCL_21_3;
	int			SCL_21_21;
	int			CLFRM_21_21;
	int			HECA_22_22;
	int			NFA_21_3;
	int			SFA_3_23;
	int			SFA_3_21;
	int			SFA_3_3;
	int			SCL_3_3;
	int			SCL_3_21;
	int			falvChecked;
	int			dmpChecked;
	int			campNum;
	int			campYear;
	int			infoRow;
	bool		full;
	bool		noOpt;
	bool		devs;
		
	retSt = GetZoneIdx(ZONE_FA_01, &zoneFA1Idx);
	retSt = GetZoneIdx(ZONE_FA_02, &zoneFA2Idx);
	retSt = GetZoneIdx(ZONE_FA_03, &zoneFA3Idx);
	retSt = GetZoneIdx(ZONE_FA_04, &zoneFA4Idx);
	retSt = GetZoneIdx(ZONE_FA_05, &zoneFA5Idx);
	retSt = GetZoneIdx(ZONE_FA_06, &zoneFA6Idx);
	retSt = GetZoneIdx(ZONE_FA_07, &zoneFA7Idx);
	retSt = GetZoneIdx(ZONE_FA_08, &zoneFA8Idx);
	retSt = GetZoneIdx(ZONE_FA_09, &zoneFA9Idx);
	retSt = GetZoneIdx(ZONE_FA_10, &zoneFA10Idx);
	retSt = GetZoneIdx(ZONE_REACTOR, &zoneReactIdx);
	retSt = GetZoneIdx(ZONE_HECA_1, &zoneHeca1Idx);
	retSt = GetZoneIdx(ZONE_HECA_2, &zoneHeca2Idx);
	retSt = GetZoneIdx(ZONE_IO, &zoneIOIdx);
	retSt = GetZoneIdx(ZONE_MAIN, &sfpIdx);
	retSt = GetZoneIdx(ZONE_FA, &zoneFAIdx);
	retSt = GetZoneIdx(ZONE_HECA, &zoneHecaIdx);
	retSt = GetZoneIdx(ZONE_FFDS, &zoneFFDSIdx);
	retSt = GetObjtIdx(_T("N_FA"), &N_FAIdx);
	retSt = GetObjtIdx(_T("S_FA"), &S_FAIdx);
	retSt = GetObjtIdx(_T("D_FA"), &D_FAIdx);
	retSt = GetObjtIdx(_T("N_CL"), &N_CLIdx);
	retSt = GetObjtIdx(_T("S_CL"), &S_CLIdx);
	retSt = GetObjtIdx(_T("HECA"), &HECAIdx);
	retSt = GetObjtIdx(_T("CLUS_FRM"), &CLFRMIdx); 

	filePhas.num = F_PHAS;
	fileCamp.num = F_CAMP;

	newFAClus = 0;
	newFA = 0;
	newClus = 0;
	spentClus = 0;
	spentFA = 0;
	spentFAClus = 0;
	clusFrm = 0;
	clusFrmClus = 0;
	Heca = 0;
	HecaFA = 0;

	fullNum = 0;
	noOpt = true;
	
	retSt = GetCamp(&camp);
	if(retSt != RT_NORMAL)
		return(retSt);

	//Prendo o costruisco il nome del file Excel.//
	GetSystemTime(&sysTime);
	sysTime.wHour = sysTime.wHour + 8;
	
	switch(reportType){
	case REP_PSAS_FA:
			excelObj = new CXlsObj;
		retI = excelObj->Init();
		if(!retI){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		retI = excelObj->OpenWorkBook(templatePSASPath, VARIANT_FALSE, 1);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		noOpt = false;
		_stprintf_s(fileName, defaultFileNamePSAS, _T("Z21"), sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute);
			
		totNum = 0;
		fullNum = 0;
		for(i = 0; i < N_MAX_ZONE; i++){
			if((i == zoneFA1Idx) || (i == zoneFA2Idx) || (i == zoneFA3Idx) || (i == zoneFA4Idx) || (i == zoneFA5Idx) ||
			   (i == zoneFA6Idx) || (i == zoneFA7Idx) || (i == zoneFA8Idx) || (i == zoneFA9Idx) || (i == zoneFA10Idx)){
				fileCell.num = F_CE01 + i - 1;
				for(j = 1; j <= N_MAX_CELL; j++){
					full = false;
					retCnd = FileRead(&fileCell, j, 1, &cell, sizeof(cell));
					if(retCnd != R_NORMAL){
						delete excelObj;
						excelObj = NULL;
						return(RT_FAILED);
					}
					
					if((cell.Virt_X == 0) || (cell.Virt_Y == 0))
						break;

					if((cell.objt_cell.obj[OBJT_N_FA] == N_FAIdx) && (cell.objt_cell.obj[OBJT_N_CLUS] == 0)){
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_X, cell.Virt_X);
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_Y, cell.Virt_Y);
						GetObjtName(cell.objt_cell.obj[OBJT_N_FA], objtName);
						GetObjName(cell.objt_cell.o_id[OBJT_N_FA], objName);
						_stprintf_s(temp, _T("%s"), objName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJ, temp);
						_stprintf_s(temp, _T("%s"), objtName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJT, temp);
						retCnd = ConvertFromApmsTimeEx (&cell.objt_cell.LastDate, &year, &month, &day, &hour, &min, &sec, &msec);
						if(year != 1991)
							_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
						else
							_stprintf_s(temp, _T("No time"));
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_DATE, temp);
						/*
						GetObjSipp(cell.objt_cell.o_id[OBJT_N_FA], &sipp);
						if(sipp.sippTimestamp.dwTime == 0){
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, _T("[--/--/-- - --:--.--]"));
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, _T("-----"));
						}
						else{
							retCnd = ConvertFromApmsTimeEx (&sipp.sippTimestamp, &year, &month, &day, &hour, &min, &sec, &msec);
							if(year != 1991)
								_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
							else
								_stprintf_s(temp, _T("No time"));
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, temp);
							excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, (double)(sipp.measActivity));
						}
						*/
						totNum++;
						fullNum++;
						newFA++;
					}
					else if ((cell.objt_cell.obj[OBJT_N_FA] == N_FAIdx) && (cell.objt_cell.obj[OBJT_N_CLUS] != 0)){
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_X, cell.Virt_X);
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_Y, cell.Virt_Y);
						GetObjtName(cell.objt_cell.obj[OBJT_N_FA], objtName);
						GetObjName(cell.objt_cell.o_id[OBJT_N_FA], objName);
						_stprintf_s(temp, _T("%s"), objName);
						GetObjName(cell.objt_cell.o_id[OBJT_N_CLUS], objName);
						_stprintf_s(temp_2, _T("%s, %s"), temp, objName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJ, temp_2);
						_stprintf_s(temp, _T("%s"), objtName);
						GetObjtName(cell.objt_cell.obj[OBJT_N_CLUS], objtName);
						_stprintf_s(temp_2, _T("%s, %s"), temp, objtName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJT, temp_2);
						retCnd = ConvertFromApmsTimeEx (&cell.objt_cell.LastDate, &year, &month, &day, &hour, &min, &sec, &msec);
						if(year != 1991)
							_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
						else
							_stprintf_s(temp, _T("No time"));
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_DATE, temp);
						/*
						GetObjSipp(cell.objt_cell.o_id[OBJT_N_FA], &sipp);
						if(sipp.sippTimestamp.dwTime == 0){
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, _T("[--/--/-- - --:--.--]"));
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, _T("-----"));
						}
						else{
							retCnd = ConvertFromApmsTimeEx (&sipp.sippTimestamp, &year, &month, &day, &hour, &min, &sec, &msec);
							if(year != 1991)
								_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
							else
								_stprintf_s(temp, _T("No time"));
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, temp);
							excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, (double)(sipp.measActivity));
						}
						*/
						totNum++;
						fullNum++;
						newFAClus++;
					}
					if(((cell.objt_cell.obj[OBJT_N_FA] == S_FAIdx) || (cell.objt_cell.obj[OBJT_N_FA] == D_FAIdx)) && (cell.objt_cell.obj[OBJT_N_CLUS] == 0)){
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_X, cell.Virt_X);
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_Y, cell.Virt_Y);
						GetObjtName(cell.objt_cell.obj[OBJT_N_FA], objtName);
						GetObjName(cell.objt_cell.o_id[OBJT_N_FA], objName);
						_stprintf_s(temp, _T("%s"), objName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJ, temp);
						_stprintf_s(temp, _T("%s"), objtName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJT, temp);
						retCnd = ConvertFromApmsTimeEx (&cell.objt_cell.LastDate, &year, &month, &day, &hour, &min, &sec, &msec);
						if(year != 1991)
							_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
						else
							_stprintf_s(temp, _T("No time"));
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_DATE, temp);
						/*
						GetObjSipp(cell.objt_cell.o_id[OBJT_N_FA], &sipp);
						if(sipp.sippTimestamp.dwTime == 0){
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, _T("[--/--/-- - --:--.--]"));
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, _T("-----"));
						}
						else{
							retCnd = ConvertFromApmsTimeEx (&sipp.sippTimestamp, &year, &month, &day, &hour, &min, &sec, &msec);
							if(year != 1991)
								_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
							else
								_stprintf_s(temp, _T("No time"));
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, temp);
							excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, (double)(sipp.measActivity));
						}
						*/
						totNum++;
						fullNum++;
						spentFA++;
					}
					else if (((cell.objt_cell.obj[OBJT_N_FA] == S_FAIdx) || (cell.objt_cell.obj[OBJT_N_FA] == D_FAIdx)) && (cell.objt_cell.obj[OBJT_N_CLUS] != 0)){
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_X, cell.Virt_X);
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_Y, cell.Virt_Y);
						GetObjtName(cell.objt_cell.obj[OBJT_N_FA], objtName);
						GetObjName(cell.objt_cell.o_id[OBJT_N_FA], objName);
						_stprintf_s(temp, _T("%s"), objName);
						GetObjName(cell.objt_cell.o_id[OBJT_N_CLUS], objName);
						_stprintf_s(temp_2, _T("%s, %s"), temp, objName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJ, temp_2);
						_stprintf_s(temp, _T("%s"), objtName);
						GetObjtName(cell.objt_cell.obj[OBJT_N_CLUS], objtName);
						_stprintf_s(temp_2, _T("%s, %s"), temp, objtName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJT, temp_2);
						retCnd = ConvertFromApmsTimeEx (&cell.objt_cell.LastDate, &year, &month, &day, &hour, &min, &sec, &msec);
						if(year != 1991)
							_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
						else
							_stprintf_s(temp, _T("No time"));
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_DATE, temp);
						/*
						GetObjSipp(cell.objt_cell.o_id[OBJT_N_FA], &sipp);
						if(sipp.sippTimestamp.dwTime == 0){
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, _T("[--/--/-- - --:--.--]"));
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, _T("-----"));
						}
						else{
							retCnd = ConvertFromApmsTimeEx (&sipp.sippTimestamp, &year, &month, &day, &hour, &min, &sec, &msec);
							if(year != 1991)
								_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
							else
								_stprintf_s(temp, _T("No time"));
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, temp);
							excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, (double)(sipp.measActivity));
						}
						*/
						totNum++;
						fullNum++;
						spentFAClus++;
					}
					else if ((cell.objt_cell.obj[OBJT_N_CLUS_FRM] == CLFRMIdx)  && (cell.objt_cell.obj[OBJT_N_CLUS] != 0)){
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_X, cell.Virt_X);
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_Y, cell.Virt_Y);
						GetObjtName(cell.objt_cell.obj[OBJT_N_CLUS_FRM], objtName);
						GetObjName(cell.objt_cell.o_id[OBJT_N_CLUS_FRM], objName);
						_stprintf_s(temp, _T("%s"), objName);
						GetObjName(cell.objt_cell.o_id[OBJT_N_CLUS], objName);
						_stprintf_s(temp_2, _T("%s, %s"), temp, objName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJ, temp_2);
						_stprintf_s(temp, _T("%s"), objtName);
						GetObjtName(cell.objt_cell.obj[OBJT_N_CLUS], objtName);
						_stprintf_s(temp_2, _T("%s, %s"), temp, objtName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJT, temp_2);
						retCnd = ConvertFromApmsTimeEx (&cell.objt_cell.LastDate, &year, &month, &day, &hour, &min, &sec, &msec);
						if(year != 1991)
							_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
						else
							_stprintf_s(temp, _T("No time"));
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_DATE, temp);
						/*
						GetObjSipp(cell.objt_cell.o_id[OBJT_N_FA], &sipp);
						if(sipp.sippTimestamp.dwTime == 0){
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, _T("[--/--/-- - --:--.--]"));
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, _T("-----"));
						}
						else{
							retCnd = ConvertFromApmsTimeEx (&sipp.sippTimestamp, &year, &month, &day, &hour, &min, &sec, &msec);
							if(year != 1991)
								_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
							else
								_stprintf_s(temp, _T("No time"));
							excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, temp);
							excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, (double)(sipp.measActivity));
						}
						*/
						totNum++;
						fullNum++;
						clusFrmClus++;
					}
					else if ((cell.objt_cell.obj[OBJT_N_CLUS_FRM] == CLFRMIdx)  && (cell.objt_cell.obj[OBJT_N_CLUS] == 0)){
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_X, cell.Virt_X);
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_Y, cell.Virt_Y);
						GetObjtName(cell.objt_cell.obj[OBJT_N_CLUS_FRM], objtName);
						GetObjName(cell.objt_cell.o_id[OBJT_N_CLUS_FRM], objName);
						_stprintf_s(temp, _T("%s"), objName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJ, temp);
						_stprintf_s(temp, _T("%s"), objtName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJT, temp);
						retCnd = ConvertFromApmsTimeEx (&cell.objt_cell.LastDate, &year, &month, &day, &hour, &min, &sec, &msec);
						if(year != 1991)
							_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
						else
							_stprintf_s(temp, _T("No time"));
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_DATE, temp);
						totNum++;
						fullNum++;
						clusFrm++;
					}
					else
						totNum++;
				}
			}
		}
		for(infoRow = XLS_ROW_INFO_FIRST; infoRow <= XLS_ROW_INFO_LAST; infoRow++){
			switch(infoRow){
			case XLS_ROW_INFO_FIRST:
				excelObj->SetCellsValueDbl(infoRow, XLS_COL_INFO, totNum);
				break;
			case XLS_ROW_INFO_FIRST + 1:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("New FA without Cluster Cells"));
				excelObj->SetCellsValueDbl(infoRow, XLS_COL_INFO, newFA);
				break;
			case XLS_ROW_INFO_FIRST + 2:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("New FA with Cluster Cells"));
				excelObj->SetCellsValueDbl(infoRow, XLS_COL_INFO, newFAClus);
				break;
			case XLS_ROW_INFO_FIRST + 3:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("Spent FA without Cluster Cells"));
				excelObj->SetCellsValueDbl(infoRow , XLS_COL_INFO, spentFA);
				break;
			case XLS_ROW_INFO_FIRST + 4:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("Spent FA with Cluster Cells"));
				excelObj->SetCellsValueDbl(infoRow , XLS_COL_INFO, spentFAClus);
				break;
			case XLS_ROW_INFO_FIRST + 5:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("Cluster Frames in Cells"));
				excelObj->SetCellsValueDbl(infoRow , XLS_COL_INFO, clusFrm);
				break;
			case XLS_ROW_INFO_FIRST + 6:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("Cluster Frames with cluster in Cells"));
				excelObj->SetCellsValueDbl(infoRow , XLS_COL_INFO, clusFrmClus);
				break;
			case XLS_ROW_INFO_LAST:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("Empty Cells"));
				excelObj->SetCellsValueDbl(infoRow , XLS_COL_INFO, totNum - fullNum);
				break;
			default:
				break;
			}
		}
		excelObj->SetCellsValueStr(XLS_ROW_DOC_TYPE, XLS_COL_DOC_TYPE, _T("Spent Fuel Pool (Area 2) - Cells for FA installation"));
		excelObj->SetCellsValueStr(XLS_ROW_DOC_NAME, XLS_COL_DOC_NAME, fileName);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_USER, XLS_COL_DOC_USER, userName);
		
		GetApmsTimeEx(&time);
		retCnd = ConvertFromApmsTimeEx (&time, &year, &month, &day, &hour, &min, &sec, &msec);
		if(year != 1991)
			_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
		else
			_stprintf_s(temp, _T("No time"));
		excelObj->SetCellsValueStr(XLS_ROW_DOC_DATE, XLS_COL_DOC_DATE, temp);

		
		retI = excelObj->SaveWorkBook(fileName);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		retI = excelObj->CloseActiveWorkBook(false);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		retI = excelObj->Close();
		delete excelObj;
		excelObj = NULL;
		
		retB = SetFileAttributes(fileName, FILE_ATTRIBUTE_READONLY);
		if(retB == 0)
			return(RT_FAILED);

		break;

	case REP_PSAS_HECA:
			excelObj = new CXlsObj;
		retI = excelObj->Init();
		if(!retI){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		retI = excelObj->OpenWorkBook(templatePSASPath, VARIANT_FALSE, 1);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		noOpt = false;
		_stprintf_s(fileName, defaultFileNamePSAS, _T("Z22"), sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute);
			
		totNum = 0;
		fullNum = 0;
		
		for(i = 0; i < N_MAX_ZONE; i++){
			if((i == zoneHeca1Idx) || (i == zoneHeca2Idx)){
				fileCell.num = F_CE01 + i - 1;
				for(j = 1; j <= N_MAX_CELL; j++){
					full = false;
					retCnd = FileRead(&fileCell, j, 1, &cell, sizeof(cell));
					if(retCnd != R_NORMAL){
						delete excelObj;
						excelObj = NULL;
						return(RT_FAILED);
					}
					
					if((cell.Virt_X == 0) || (cell.Virt_Y == 0))
						break;
					if((cell.objt_cell.obj[OBJT_N_HECA] == HECAIdx) && (cell.objt_cell.obj[OBJT_N_FA] == 0)){
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_X, cell.Virt_X);
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_Y, cell.Virt_Y);
						GetObjtName(cell.objt_cell.obj[OBJT_N_HECA], objtName);
						GetObjName(cell.objt_cell.o_id[OBJT_N_HECA], objName);
						if(cell.objt_cell.obj[OBJT_N_COVER] != 0){
							GetObjtName(cell.objt_cell.obj[OBJT_N_COVER], objtName_1);
							GetObjName(cell.objt_cell.o_id[OBJT_N_COVER], objName_1);
							_stprintf_s(temp, _T("%s, %s"), objName, objName_1);
						}
						else
							_stprintf_s(temp, _T("%s"), objName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJ, temp);
						_stprintf_s(temp, _T("%s, %s"), objtName, objtName_1);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJT, temp);
						retCnd = ConvertFromApmsTimeEx (&cell.objt_cell.LastDate, &year, &month, &day, &hour, &min, &sec, &msec);
						if(year != 1991)
							_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
						else
							_stprintf_s(temp, _T("No time"));
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_DATE, temp);
						totNum++;
						fullNum++;
						Heca++;
					}

					else if ((cell.objt_cell.obj[OBJT_N_HECA] == HECAIdx) && (cell.objt_cell.obj[OBJT_N_FA] != 0)){
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_X, cell.Virt_X);
						excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_Y, cell.Virt_Y);
						GetObjtName(cell.objt_cell.obj[OBJT_N_HECA], objtName);
						GetObjName(cell.objt_cell.o_id[OBJT_N_HECA], objName);
						
						if(cell.objt_cell.obj[OBJT_N_COVER] != 0){
							GetObjtName(cell.objt_cell.obj[OBJT_N_COVER], objtName_1);
							GetObjName(cell.objt_cell.o_id[OBJT_N_COVER], objName_1);
							_stprintf_s(temp, _T("%s, %s"), objName, objName_1);
							_stprintf_s(temp_2, _T("%s, %s"), objtName, objtName_1);
						}
						else{
							_stprintf_s(temp, _T("%s"), objName);
							_stprintf_s(temp_2, _T("%s"), objtName);
						}
						
						GetObjName(cell.objt_cell.o_id[OBJT_N_FA], objName);
						_stprintf_s(temp_3, _T("%s, %s"), temp, objName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJ, temp_3);
						_stprintf_s(temp, _T("%s"), objtName);
						GetObjtName(cell.objt_cell.obj[OBJT_N_FA], objtName);
						_stprintf_s(temp_3, _T("%s, %s"), temp_2, objtName);
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJT, temp_3);
						retCnd = ConvertFromApmsTimeEx (&cell.objt_cell.LastDate, &year, &month, &day, &hour, &min, &sec, &msec);
						if(year != 1991)
							_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
						else
							_stprintf_s(temp, _T("No time"));
						excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_DATE, temp);
						totNum++;
						fullNum++;
						HecaFA++;
					}
					else
						totNum++;
				}
			}
		}
				
		for(infoRow = XLS_ROW_INFO_FIRST; infoRow <= XLS_ROW_INFO_LAST; infoRow++){
			switch(infoRow){
			case XLS_ROW_INFO_FIRST:
				excelObj->SetCellsValueDbl(infoRow, XLS_COL_INFO, totNum);
				break;
			case XLS_ROW_INFO_FIRST + 1:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("Hermetic casks without FA"));
				excelObj->SetCellsValueDbl(infoRow, XLS_COL_INFO, Heca);
				break;
			case XLS_ROW_INFO_FIRST + 2:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("Hermetic casks with FA"));
				excelObj->SetCellsValueDbl(infoRow, XLS_COL_INFO, HecaFA);
				break;
			case XLS_ROW_INFO_FIRST + 3:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("Empty Cells"));
				excelObj->SetCellsValueDbl(infoRow , XLS_COL_INFO, totNum - fullNum);
				break;
			case XLS_ROW_INFO_FIRST + 4:
				break;
			case XLS_ROW_INFO_LAST:
				break;
			default:
				break;
			}
		}
		excelObj->SetCellsValueStr(XLS_ROW_DOC_TYPE, XLS_COL_DOC_TYPE, _T("Spent Fuel Pool (Area 2) - Cells for Hermetic Casks instal."));
		excelObj->SetCellsValueStr(XLS_ROW_DOC_NAME, XLS_COL_DOC_NAME, fileName);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_USER, XLS_COL_DOC_USER, userName);
		
		GetApmsTimeEx(&time);
		retCnd = ConvertFromApmsTimeEx (&time, &year, &month, &day, &hour, &min, &sec, &msec);
		if(year != 1991)
			_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
		else
			_stprintf_s(temp, _T("No time"));
		excelObj->SetCellsValueStr(XLS_ROW_DOC_DATE, XLS_COL_DOC_DATE, temp);

		retI = excelObj->SaveWorkBook(fileName);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		retI = excelObj->CloseActiveWorkBook(false);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->Close();
		delete excelObj;
		excelObj = NULL;
		
		retB = SetFileAttributes(fileName, FILE_ATTRIBUTE_READONLY);
		if(retB == 0)
			return(RT_FAILED);

		break;

	case REP_PSAS_REACT:
			excelObj = new CXlsObj;
		retI = excelObj->Init();
		if(!retI){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
	
		retI = excelObj->OpenWorkBook(templatePSASPath, VARIANT_FALSE, 1);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		noOpt = false;
		
		_stprintf_s(fileName, defaultFileNamePSAS, _T("Z3"), sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute);
			
		_stprintf_s(echoMsg, _T("Building report for Cells for FA installation in Reactor."));
		
		totNum = 0;
		fullNum = 0;
		/*
		newFA = 0;
		newFAClus = 0;
		spentFA = 0;
		spentFAClus = 0;
		*/
		fileCell.num = F_CE01 + zoneReactIdx - 1;

		for(j = 1; j <= N_MAX_CELL; j++){
			full = false;
			retCnd = FileRead(&fileCell, j, 1, &cell, sizeof(cell));
			if(retCnd != R_NORMAL){
				delete excelObj;
				excelObj = NULL;
				return(RT_FAILED);
			}
					
			if((cell.Virt_X == 0) || (cell.Virt_Y == 0))
				break;

			if((cell.objt_cell.obj[OBJT_N_FA] == N_FAIdx) && (cell.objt_cell.obj[OBJT_N_CLUS] == 0)){
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_X, cell.Virt_X);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_Y, cell.Virt_Y);
				GetObjtName(cell.objt_cell.obj[OBJT_N_FA], objtName);
				GetObjName(cell.objt_cell.o_id[OBJT_N_FA], objName);
				_stprintf_s(temp, _T("%s"), objName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJ, temp);
				_stprintf_s(temp, _T("%s"), objtName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJT, temp);
				retCnd = ConvertFromApmsTimeEx (&cell.objt_cell.LastDate, &year, &month, &day, &hour, &min, &sec, &msec);
				if(year != 1991)
					_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
				else
					_stprintf_s(temp, _T("No time"));
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_DATE, temp);
				/*
				GetObjSipp(cell.objt_cell.o_id[OBJT_N_FA], &sipp);
				if(sipp.sippTimestamp.dwTime == 0){
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, _T("[--/--/-- - --:--.--]"));
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, _T("-----"));
				}
				else{
					retCnd = ConvertFromApmsTimeEx (&sipp.sippTimestamp, &year, &month, &day, &hour, &min, &sec, &msec);
					if(year != 1991)
						_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
					else
						_stprintf_s(temp, _T("No time"));
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, temp);
					excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, (double)(sipp.measActivity));
				}
				*/
				totNum++;
				fullNum++;
				newFA++;
			}
			else if ((cell.objt_cell.obj[OBJT_N_FA] == N_FAIdx) && (cell.objt_cell.obj[OBJT_N_CLUS] != 0)){
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_X, cell.Virt_X);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_Y, cell.Virt_Y);
				GetObjtName(cell.objt_cell.obj[OBJT_N_FA], objtName);
				GetObjName(cell.objt_cell.o_id[OBJT_N_FA], objName);
				_stprintf_s(temp, _T("%s"), objName);
				GetObjName(cell.objt_cell.o_id[OBJT_N_CLUS], objName);
				_stprintf_s(temp_2, _T("%s, %s"), temp, objName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJ, temp_2);
				_stprintf_s(temp, _T("%s"), objtName);
				GetObjtName(cell.objt_cell.obj[OBJT_N_CLUS], objtName);
				_stprintf_s(temp_2, _T("%s, %s"), temp, objtName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJT, temp_2);
				retCnd = ConvertFromApmsTimeEx (&cell.objt_cell.LastDate, &year, &month, &day, &hour, &min, &sec, &msec);
				if(year != 1991)
					_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
				else
					_stprintf_s(temp, _T("No time"));
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_DATE, temp);
				/*
				GetObjSipp(cell.objt_cell.o_id[OBJT_N_FA], &sipp);
				if(sipp.sippTimestamp.dwTime == 0){
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, _T("[--/--/-- - --:--.--]"));
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, _T("-----"));
				}
				else{
					retCnd = ConvertFromApmsTimeEx (&sipp.sippTimestamp, &year, &month, &day, &hour, &min, &sec, &msec);
					if(year != 1991)
						_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
					else
						_stprintf_s(temp, _T("No time"));
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, temp);
					excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, (double)(sipp.measActivity));
				}
				*/
				totNum++;
				fullNum++;
				newFAClus++;
			}
			if(((cell.objt_cell.obj[OBJT_N_FA] == S_FAIdx) || (cell.objt_cell.obj[OBJT_N_FA] == D_FAIdx)) && (cell.objt_cell.obj[OBJT_N_CLUS] == 0)){
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_X, cell.Virt_X);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_Y, cell.Virt_Y);
				GetObjtName(cell.objt_cell.obj[OBJT_N_FA], objtName);
				GetObjName(cell.objt_cell.o_id[OBJT_N_FA], objName);
				_stprintf_s(temp, _T("%s"), objName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJ, temp);
				_stprintf_s(temp, _T("%s"), objtName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJT, temp);
				retCnd = ConvertFromApmsTimeEx (&cell.objt_cell.LastDate, &year, &month, &day, &hour, &min, &sec, &msec);
				if(year != 1991)
					_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
				else
					_stprintf_s(temp, _T("No time"));
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_DATE, temp);
				/*
				GetObjSipp(cell.objt_cell.o_id[OBJT_N_FA], &sipp);
				if(sipp.sippTimestamp.dwTime == 0){
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, _T("[--/--/-- - --:--.--]"));
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, _T("-----"));
				}
				else{
					retCnd = ConvertFromApmsTimeEx (&sipp.sippTimestamp, &year, &month, &day, &hour, &min, &sec, &msec);
					if(year != 1991)
						_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
					else
						_stprintf_s(temp, _T("No time"));
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, temp);
					excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, (double)(sipp.measActivity));
				}
				*/
				totNum++;
				fullNum++;
				spentFA++;
			}
			else if (((cell.objt_cell.obj[OBJT_N_FA] == S_FAIdx) || (cell.objt_cell.obj[OBJT_N_FA] == D_FAIdx)) && (cell.objt_cell.obj[OBJT_N_CLUS] != 0)){
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_X, cell.Virt_X);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_VIRT_Y, cell.Virt_Y);
				GetObjtName(cell.objt_cell.obj[OBJT_N_FA], objtName);
				GetObjName(cell.objt_cell.o_id[OBJT_N_FA], objName);
				_stprintf_s(temp, _T("%s"), objName);
				GetObjName(cell.objt_cell.o_id[OBJT_N_CLUS], objName);
				_stprintf_s(temp_2, _T("%s, %s"), temp, objName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJ, temp_2);
				_stprintf_s(temp, _T("%s"), objtName);
				GetObjtName(cell.objt_cell.obj[OBJT_N_CLUS], objtName);
				_stprintf_s(temp_2, _T("%s, %s"), temp, objtName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_OBJT, temp_2);
				retCnd = ConvertFromApmsTimeEx (&cell.objt_cell.LastDate, &year, &month, &day, &hour, &min, &sec, &msec);
				if(year != 1991)
					_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
				else
					_stprintf_s(temp, _T("No time"));
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_DATE, temp);
				/*
				GetObjSipp(cell.objt_cell.o_id[OBJT_N_FA], &sipp);
				if(sipp.sippTimestamp.dwTime == 0){
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, _T("[--/--/-- - --:--.--]"));
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, _T("-----"));
				}
				else{
					retCnd = ConvertFromApmsTimeEx (&sipp.sippTimestamp, &year, &month, &day, &hour, &min, &sec, &msec);
					if(year != 1991)
						_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
					else
						_stprintf_s(temp, _T("No time"));
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_DATE, temp);
					excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT + fullNum, XLS_COL_SIPP_RES, (double)(sipp.measActivity));
				}
				*/

				totNum++;
				fullNum++;
				spentFAClus++;
			}
			else
				totNum++;
		}
		for(infoRow = XLS_ROW_INFO_FIRST; infoRow <= XLS_ROW_INFO_LAST; infoRow++){
			switch(infoRow){
			case XLS_ROW_INFO_FIRST:
				excelObj->SetCellsValueDbl(infoRow, XLS_COL_INFO, totNum);
				break;
			case XLS_ROW_INFO_FIRST + 1:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("New FA without Cluster Cells"));
				excelObj->SetCellsValueDbl(infoRow, XLS_COL_INFO, newFA);
				break;
			case XLS_ROW_INFO_FIRST + 2:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("New FA with Cluster Cells"));
				excelObj->SetCellsValueDbl(infoRow, XLS_COL_INFO, newFAClus);
				break;
			case XLS_ROW_INFO_FIRST + 3:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("Spent FA without Cluster Cells"));
				excelObj->SetCellsValueDbl(infoRow , XLS_COL_INFO, spentFA);
				break;
			case XLS_ROW_INFO_FIRST + 4:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("Spent FA with Cluster Cells"));
				excelObj->SetCellsValueDbl(infoRow , XLS_COL_INFO, spentFAClus);
				break;
			case XLS_ROW_INFO_FIRST + 5:
				excelObj->SetCellsValueStr(infoRow, XLS_COL_INFO_TYPE, _T("Empty Cells"));
				excelObj->SetCellsValueDbl(infoRow , XLS_COL_INFO, totNum - fullNum);
				break;
			default:
				break;
			}
		}
		excelObj->SetCellsValueStr(XLS_ROW_DOC_TYPE, XLS_COL_DOC_TYPE, _T("Reactor (Area 4) - Cells for FA installation"));
		excelObj->SetCellsValueStr(XLS_ROW_DOC_NAME, XLS_COL_DOC_NAME, fileName);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_USER, XLS_COL_DOC_USER, userName);
		
		GetApmsTimeEx(&time);
		retCnd = ConvertFromApmsTimeEx (&time, &year, &month, &day, &hour, &min, &sec, &msec);
		if(year != 1991)
			_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
		else
			_stprintf_s(temp, _T("No time"));
		excelObj->SetCellsValueStr(XLS_ROW_DOC_DATE, XLS_COL_DOC_DATE, temp);

		retI = excelObj->SaveWorkBook(fileName);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		retI = excelObj->CloseActiveWorkBook(false);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->Close();
		delete excelObj;
		excelObj = NULL;
	
		retB = SetFileAttributes(fileName, FILE_ATTRIBUTE_READONLY);
		if(retB == 0)
			return(RT_FAILED);

		break;

	//Costruzione report Refuelling Protocol per la zona I/O in carico.//
	case REP_RP_LOAD:
		excelObj = new CXlsObj;
		retI = excelObj->Init();
		if(!retI){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->OpenWorkBook(templateRPPath, VARIANT_FALSE, 1);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		noOpt = false;
		_stprintf_s(fileName, defaultFileNameRP, _T("LOAD"), sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute);
		
		//Prelevo i dati.//
		NFA_1_21 = 0;
		NFA_1_3 = 0;
		NCL_1_21 = 0;
		NCL_1_3 = 0;
		HECA_1_22 = 0;
		totNum = 0;
		for(i = 1; i < N_MAX_PHASE; i++){
			retCnd = FileRead(&filePhas, i, 1, &phas, sizeof(phas_struc));
			if(retCnd != R_NORMAL){
				delete excelObj;
				excelObj = NULL;
				return(RT_FAILED);
			}
			
			GetZoneIdxVirtCoo(phas.SV_X, phas.SV_Y, &startZoneIdx);
			GetZoneIdxVirtCoo(phas.DV_X, phas.DV_Y, &destZoneIdx);
			
			if(phas.phase == 0)
				break;
			if(phas.tecCycIdx == 0)
				continue;
			if(startZoneIdx != zoneIOIdx)
				continue;

			retSt = CheckSuperZone(destZoneIdx, zoneFAIdx);
			if(retSt == RT_NORMAL)
				destZoneIdx = zoneFAIdx;
			else{
				retSt = CheckSuperZone(destZoneIdx, zoneHecaIdx);
				if(retSt == RT_NORMAL)
					destZoneIdx = zoneHecaIdx;
			}
			
			retSt = GetObjtIdx(phas.obj_type, &objtIdx);
			retSt = GetObjIdx(phas.object, &objIdx);
			
			if(destZoneIdx == zoneFAIdx){
				if(objtIdx == N_FAIdx)
					NFA_1_21++;
				else if(objtIdx == N_CLIdx)
					NCL_1_21++;
			}
			else if(destZoneIdx == zoneReactIdx){
				if(objtIdx == N_FAIdx)
					NFA_1_3++;
				else if(objtIdx == N_CLIdx)
					NCL_1_3++;
			}
			else if(destZoneIdx == zoneHecaIdx){
				if(objtIdx == HECAIdx)
					HECA_1_22++;
			}
			else
				continue;

			if(phas.campNum == camp.seqNum){
				totNum++;
				if(phas.tecCycIdx != 0){
					retSt = GetTechCycId(phas.tecCycIdx, tcId);
					retSt = GetTechCycDescription(tcId, tcDescr);
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCID_RP, tcId);
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCDESCR_RP, tcDescr);
				}
				else{
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCID_RP, _T("N/A"));
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCDESCR_RP, phas.cmd_type);
				}
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_OBJE_RP, phas.object);
				GetObjtIdx(phas.obj_type, &genIdx);
				GetObjtDescription(genIdx, temp);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_OBJT_RP, temp);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_SVX_RP, phas.SV_X);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_SVY_RP, phas.SV_Y);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_DVX_RP, phas.DV_X);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_DVY_RP, phas.DV_Y);
				retCnd = ConvertFromApmsTimeEx (&phas.sta_phse_time, &year, &month, &day, &hour, &min, &sec, &msec);
				if(year != 1991)
					_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), day, month, year, hour, min, sec);
				else
					_stprintf_s(temp, _T("No time"));
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_STTI_RP, temp);
				retCnd = ConvertFromApmsTimeEx (&phas.end_phse_time, &year, &month, &day, &hour, &min, &sec, &msec);
				if(year != 1991)
					_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), day, month, year, hour, min, sec);
				else
					_stprintf_s(temp, _T("No time"));
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_ENTI_RP, temp);
				devs = false;
				switch(phas.esito){
				case PHAS_TOEXECUTE:
					_stprintf_s(temp, _T("Still to execute"));
					break;
				case PHAS_EXECUTED:
					_stprintf_s(temp, _T("Exexuted"));
					break;
				case PHAS_FAILED:
					_stprintf_s(temp, _T("Failed"));
					break;
				case PHAS_PLANNED:
					_stprintf_s(temp, _T("Planned"));
					break;
				case PHAS_INTERRUPTED:
					_stprintf_s(temp, _T("Interrupted"));
					break;
				case PHAS_INEXECUTION:
					_stprintf_s(temp, _T("In progress"));
					break;
				case PHAS_SUSPENDED:
					_stprintf_s(temp, _T("Suspended"));
					break;
				default:
					_stprintf_s(temp, _T("Unknown status"));
					break;
				}
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_STATUS_RP, temp);
				GetUserNameFromIdx(phas.startCondUserIdx, phUserName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_OPERATOR_SP, phUserName);
				GetUserNameFromIdx(phas.phConf.userIdx, phUserName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_SUPVIS_SP, phUserName);
			}	
		}

		//Compilo i campi con i dati del documento e con i contatori.//
		excelObj->SetCellsValueStr(XLS_ROW_DOC_NAME_RP, XLS_COL_DATA, fileName);
		_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_DATE_RP, XLS_COL_DATA, temp);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_TYPE_RP, XLS_COL_DATA, _T("Load operations from Zone 1"));
		_stprintf_s(temp, _T("Refuelling Campaign N� %d, year %d"), camp.seqNum, camp.year);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_CAMP_RP, XLS_COL_DATA, temp);
		excelObj->SetCellsValueDbl(XLS_ROW_DOC_TOTC_RP, XLS_COL_DATA, totNum);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_USER_RP, XLS_COL_DATA, userName);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT, XLS_COL_TECCYC_DESCR, _T("New FA displaced from Zone 1 to Spent Fuel Pool (Z21)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT, XLS_COL_TECCYC_NUM, NFA_1_21);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 1, XLS_COL_TECCYC_DESCR, _T("New FA displaced from Zone 1 to Reactor (Z3)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 1, XLS_COL_TECCYC_NUM, NFA_1_3);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 2, XLS_COL_TECCYC_DESCR, _T("New Clusters displaced from Zone 1 to Spent Fuel Pool (Z21)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 2, XLS_COL_TECCYC_NUM, NCL_1_21);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 3, XLS_COL_TECCYC_DESCR, _T("New Clusters displaced from Zone 1 to Reactor (Z3)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 3, XLS_COL_TECCYC_NUM, NCL_1_3);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 4, XLS_COL_TECCYC_DESCR, _T("New Hermetic cask displaced from Zone 1 to Spent Fuel Pool (Z22)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 4, XLS_COL_TECCYC_NUM, HECA_1_22);
		
		retI = excelObj->SaveWorkBook(fileName);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->CloseActiveWorkBook(false);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->Close();
		delete excelObj;
		excelObj = NULL;

		retB = SetFileAttributes(fileName, FILE_ATTRIBUTE_READONLY);
		if(retB == 0)
			return(RT_FAILED);

		break;

	//Costruzione report Refuelling Protocol per la zona I/O in scarico.//
	case REP_RP_UNLOAD:
		excelObj = new CXlsObj;
		retI = excelObj->Init();
		if(!retI){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->OpenWorkBook(templateRPPath, VARIANT_FALSE, 1);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		noOpt = false;
		_stprintf_s(fileName, defaultFileNameRP, _T("UNLOAD"), sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute);
		
		//Prelevo i dati.//
		SFA_21_1 = 0;
		SCL_21_1 = 0;
		CLFRM_21_1 = 0;
		HECA_DFA_22_1 = 0;
		totNum = 0;
		for(i = 1; i < N_MAX_PHASE; i++){
			retCnd = FileRead(&filePhas, i, 1, &phas, sizeof(phas_struc));
			if(retCnd != R_NORMAL){
				delete excelObj;
				excelObj = NULL;
				return(RT_FAILED);
			}
			
			GetZoneIdxVirtCoo(phas.SV_X, phas.SV_Y, &startZoneIdx);
			GetZoneIdxVirtCoo(phas.DV_X, phas.DV_Y, &destZoneIdx);
			
			if(phas.phase == 0)
				break;
			if(phas.tecCycIdx == 0)
				continue;
			if(destZoneIdx != zoneIOIdx)
				continue;

			retSt = GetObjtIdx(phas.obj_type, &objtIdx);
			retSt = GetObjIdx(phas.object, &objIdx);

			if(CheckSuperZone(startZoneIdx, zoneFAIdx) == RT_NORMAL){
				if(objtIdx == S_FAIdx)
					SFA_21_1++;
				else if(objtIdx == S_CLIdx)
					SCL_21_1++;
				else if(objtIdx == CLFRMIdx)
					CLFRM_21_1++;
			}
			else if(CheckSuperZone(startZoneIdx, zoneHecaIdx) == RT_NORMAL){
				if(objtIdx == HECAIdx)
					HECA_DFA_22_1++;
			}
			else 
				continue;
			

			if(phas.campNum == camp.seqNum){
				totNum++;
				if(phas.tecCycIdx != 0){
					retSt = GetTechCycId(phas.tecCycIdx, tcId);
					retSt = GetTechCycDescription(tcId, tcDescr);
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCID_RP, tcId);
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCDESCR_RP, tcDescr);
				}
				else{
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCID_RP, _T("N/A"));
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCDESCR_RP, phas.cmd_type);
				}
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_OBJE_RP, phas.object);
				GetObjtIdx(phas.obj_type, &genIdx);
				GetObjtDescription(genIdx, temp);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_OBJT_RP, temp);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_SVX_RP, phas.SV_X);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_SVY_RP, phas.SV_Y);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_DVX_RP, phas.DV_X);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_DVY_RP, phas.DV_Y);
				retCnd = ConvertFromApmsTimeEx (&phas.sta_phse_time, &year, &month, &day, &hour, &min, &sec, &msec);
				if(year != 1991)
					_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), day, month, year, hour, min, sec);
				else
					_stprintf_s(temp, _T("No time"));
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_STTI_RP, temp);
				retCnd = ConvertFromApmsTimeEx (&phas.end_phse_time, &year, &month, &day, &hour, &min, &sec, &msec);
				if(year != 1991)
					_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), day, month, year, hour, min, sec);
				else
					_stprintf_s(temp, _T("No time"));
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_ENTI_RP, temp);
				devs = false;
				switch(phas.esito){
				case PHAS_TOEXECUTE:
					_stprintf_s(temp, _T("Still to execute"));
					break;
				case PHAS_EXECUTED:
					_stprintf_s(temp, _T("Exexuted"));
					break;
				case PHAS_FAILED:
					_stprintf_s(temp, _T("Failed"));
					break;
				case PHAS_PLANNED:
					_stprintf_s(temp, _T("Planned"));
					break;
				case PHAS_INTERRUPTED:
					_stprintf_s(temp, _T("Interrupted"));
					break;
				case PHAS_INEXECUTION:
					_stprintf_s(temp, _T("In progress"));
					break;
				case PHAS_SUSPENDED:
					_stprintf_s(temp, _T("Suspended"));
					break;
				default:
					_stprintf_s(temp, _T("Unknown status"));
					break;
				}
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_STATUS_RP, temp);
				GetUserNameFromIdx(phas.startCondUserIdx, phUserName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_OPERATOR_SP, phUserName);
				GetUserNameFromIdx(phas.phConf.userIdx, phUserName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_SUPVIS_SP, phUserName);
			}	
		}

		//Compilo i campi con i dati del documento e con i contatori.//
		excelObj->SetCellsValueStr(XLS_ROW_DOC_NAME_RP, XLS_COL_DATA, fileName);
		_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_DATE_RP, XLS_COL_DATA, temp);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_TYPE_RP, XLS_COL_DATA, _T("Load operations from Zone 1"));
		_stprintf_s(temp, _T("Refuelling Campaign N� %d, year %d"), camp.seqNum, camp.year);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_CAMP_RP, XLS_COL_DATA, temp);
		excelObj->SetCellsValueDbl(XLS_ROW_DOC_TOTC_RP, XLS_COL_DATA, totNum);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_USER_RP, XLS_COL_DATA, userName);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT, XLS_COL_TECCYC_DESCR, _T("Spent FA displaced from Spent Fuel Pool (Z21) to Zone 1"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT, XLS_COL_TECCYC_NUM, SFA_21_1);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 1, XLS_COL_TECCYC_DESCR, _T("Spent Clusters displaced from Spent Fuel Pool (Z21) to Zone 1"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 1, XLS_COL_TECCYC_NUM, SCL_21_1);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 2, XLS_COL_TECCYC_DESCR, _T("Cluster Frames displaced from Spent Fuel Pool (Z21) to Zone 1"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 2, XLS_COL_TECCYC_NUM, CLFRM_21_1);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 3, XLS_COL_TECCYC_DESCR, _T("Hermetic Casks with defect FA unloaded in Z1"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 3, XLS_COL_TECCYC_NUM, HECA_DFA_22_1);
		
		retI = excelObj->SaveWorkBook(fileName);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->CloseActiveWorkBook(false);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->Close();
		delete excelObj;
		excelObj = NULL;
		
		retB = SetFileAttributes(fileName, FILE_ATTRIBUTE_READONLY);
		if(retB == 0)
			return(RT_FAILED);

		break;

	//Costruzione report Refuelling Protocol per la zona SFP (Z21 + Z22).//
	case REP_RP_SFP:
		excelObj = new CXlsObj;
		retI = excelObj->Init();
		if(!retI){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		retI = excelObj->OpenWorkBook(templateRPPath, VARIANT_FALSE, 1);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		noOpt = false;
		_stprintf_s(fileName, defaultFileNameRP, _T("SFP"), sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute);
			
		//Prelevo i dati.//
		SFA_21_21 = 0;
		SFA_23_21 = 0;
		DFA_23_22 = 0;
		NCL_21_3 = 0;
		SCL_21_21 = 0;
		CLFRM_21_21 = 0;
		HECA_22_22 = 0;
		NFA_21_3 = 0;
		totNum = 0;
		for(i = 1; i < N_MAX_PHASE; i++){
			retCnd = FileRead(&filePhas, i, 1, &phas, sizeof(phas_struc));
			if(retCnd != R_NORMAL){
				delete excelObj;
				excelObj = NULL;
				return(RT_FAILED);
			}
			
			if(phas.phase == 0)
				continue;

			GetZoneIdxVirtCoo(phas.SV_X, phas.SV_Y, &startZoneIdx);
			GetZoneIdxVirtCoo(phas.DV_X, phas.DV_Y, &destZoneIdx);
			
			retSt = GetObjtIdx(phas.obj_type, &objtIdx);
			retSt = GetObjIdx(phas.object, &objIdx);

			if(CheckSuperZone(startZoneIdx, sfpIdx) == RT_NORMAL){
				//Cicli con partenza in Z21//
				if(CheckSuperZone(startZoneIdx, zoneFAIdx) == RT_NORMAL){
					//Arrivo in Z21//
					if(CheckSuperZone(destZoneIdx, zoneFAIdx) == RT_NORMAL){
						if(objtIdx == S_FAIdx)
							SFA_21_21++;
						else if(objtIdx == S_CLIdx)
							SCL_21_21++;
						else if(objtIdx == CLFRMIdx)
							CLFRM_21_21++;
					}
					//Arrivo in Z3//
					else if(destZoneIdx == zoneReactIdx){
						if(objtIdx == N_CLIdx)
							NCL_21_3++;
						else if(objtIdx == N_FAIdx)
							NFA_21_3++;
					}
				}
				//Cicli in partenza da Z22//
				else if(CheckSuperZone(startZoneIdx, zoneHecaIdx) == RT_NORMAL){
					if(CheckSuperZone(destZoneIdx, zoneHecaIdx) == RT_NORMAL){
						if(objtIdx ==	HECAIdx)
							HECA_22_22++;
					}
				}
				//Cicli con partenza in Z23//
				else if(startZoneIdx == zoneFFDSIdx){
					//Arrivo in Z21//
					if(CheckSuperZone(destZoneIdx, zoneFAIdx) == RT_NORMAL){
						if(objtIdx == S_FAIdx)
							SFA_23_21++;
					}
					//Arrivo in Z22//
					else if(CheckSuperZone(destZoneIdx, zoneHecaIdx) == RT_NORMAL){
						if(objtIdx == D_FAIdx)
							DFA_23_22++;
					}
				}
			}
			else
				continue;
					
			if(phas.campNum == camp.seqNum){
				totNum++;
				if(phas.tecCycIdx != 0){
					retSt = GetTechCycId(phas.tecCycIdx, tcId);
					retSt = GetTechCycDescription(tcId, tcDescr);
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCID_RP, tcId);
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCDESCR_RP, tcDescr);
				}
				else{
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCID_RP, _T("N/A"));
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCDESCR_RP, phas.cmd_type);
				}
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_OBJE_RP, phas.object);
				GetObjtIdx(phas.obj_type, &genIdx);
				GetObjtDescription(genIdx, temp);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_OBJT_RP, temp);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_SVX_RP, phas.SV_X);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_SVY_RP, phas.SV_Y);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_DVX_RP, phas.DV_X);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_DVY_RP, phas.DV_Y);
				/*
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_PRAL_RP, phas.quoteTrans);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_CUAL_RP, phas.quoteInst);
				*/
				
				retCnd = ConvertFromApmsTimeEx (&phas.sta_phse_time, &year, &month, &day, &hour, &min, &sec, &msec);
				if(year != 1991)
					_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), day, month, year, hour, min, sec);
				else
					_stprintf_s(temp, _T("No time"));
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_STTI_RP, temp);
				retCnd = ConvertFromApmsTimeEx (&phas.end_phse_time, &year, &month, &day, &hour, &min, &sec, &msec);
				if(year != 1991)
					_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), day, month, year, hour, min, sec);
				else
					_stprintf_s(temp, _T("No time"));
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_ENTI_RP, temp);
				switch(phas.esito){
				case PHAS_TOEXECUTE:
					_stprintf_s(temp, _T("Still to execute"));
					break;
				case PHAS_EXECUTED:
					_stprintf_s(temp, _T("Exexuted"));
					break;
				case PHAS_FAILED:
					_stprintf_s(temp, _T("Failed"));
					break;
				case PHAS_INTERRUPTED:
					_stprintf_s(temp, _T("Interrupted"));
					break;
				case PHAS_PLANNED:
					_stprintf_s(temp, _T("Planned"));
					break;
				case PHAS_INEXECUTION:
					_stprintf_s(temp, _T("In progress"));
					break;
				case PHAS_SUSPENDED:
					_stprintf_s(temp, _T("Suspended"));
					break;
				default:
					_stprintf_s(temp, _T("Unknown status"));
					break;
				}
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_STATUS_RP, temp);
				GetUserNameFromIdx(phas.startCondUserIdx, phUserName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_OPERATOR_SP, phUserName);
				GetUserNameFromIdx(phas.phConf.userIdx, phUserName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_SUPVIS_SP, phUserName);
			}	
		}

		//Compilo i campi con i dati del documento e con i contatori.//
		excelObj->SetCellsValueStr(XLS_ROW_DOC_NAME_RP, XLS_COL_DATA, fileName);
		_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_DATE_RP, XLS_COL_DATA, temp);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_TYPE_RP, XLS_COL_DATA, _T("Spent Fuel Pool (Z2) Report"));
		_stprintf_s(temp, _T("Refuelling Campaign N� %d, year %d"), camp.seqNum, camp.year);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_CAMP_RP, XLS_COL_DATA, temp);
		excelObj->SetCellsValueDbl(XLS_ROW_DOC_TOTC_RP, XLS_COL_DATA, totNum);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_USER_RP, XLS_COL_DATA, userName);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT, XLS_COL_TECCYC_DESCR, _T("New FA displaced from Spent Fuel Pool (Z21) to Reactor (Z3)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT, XLS_COL_TECCYC_NUM, NFA_21_3);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 1, XLS_COL_TECCYC_DESCR, _T("Spent FA displaced from Spent Fuel Pool (Z21) to Spent Fuel Pool (Z21)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 1, XLS_COL_TECCYC_NUM, SFA_21_21);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 2, XLS_COL_TECCYC_DESCR, _T("Spent FA displaced from FFDS Zone (Z23) to Spent Fuel Pool (Z21)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 2, XLS_COL_TECCYC_NUM, SFA_23_21);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 3, XLS_COL_TECCYC_DESCR, _T("Defect FA displaced from FFDS Zone (Z23) to Spent Fuel Pool (Z22)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 3, XLS_COL_TECCYC_NUM, DFA_23_22);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 4, XLS_COL_TECCYC_DESCR, _T("New Clusters displaced from Spent Fuel Pool (Z21) to Reactor (Z3)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 4, XLS_COL_TECCYC_NUM, NCL_21_3);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 5, XLS_COL_TECCYC_DESCR, _T("Spent Clusters displaced from Spent Fuel Pool (Z21) to Spent Fuel Pool (Z21)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 5, XLS_COL_TECCYC_NUM, SCL_21_21);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 6, XLS_COL_TECCYC_DESCR, _T("Cluster Frames displaced from Spent Fuel Pool (Z21) to Spent Fuel Pool (Z21)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 6, XLS_COL_TECCYC_NUM, CLFRM_21_21);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 7, XLS_COL_TECCYC_DESCR, _T("Hermetic Casks displaced from Spent Fuel Pool (Z22) to Spent Fuel Pool (Z22)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 7, XLS_COL_TECCYC_NUM, HECA_22_22);
		
		retI = excelObj->SaveWorkBook(fileName);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->CloseActiveWorkBook(false);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->Close();
		delete excelObj;
		excelObj = NULL;
		
		retB = SetFileAttributes(fileName, FILE_ATTRIBUTE_READONLY);
		if(retB == 0)
			return(RT_FAILED);

		break;

	//Costruzione report Refuelling Protocol per la zona React.// zz
	case REP_RP_REACT:
		excelObj = new CXlsObj;
		retI = excelObj->Init();
		if(!retI){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->OpenWorkBook(templateRPPath, VARIANT_FALSE, 1);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		noOpt = false;
		_stprintf_s(fileName, defaultFileNameRP, _T("REA"), sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute);
		
		//Prelevo i dati.//
		SFA_3_23 = 0;
		SFA_3_21 = 0;
		SFA_3_3 = 0;
		SCL_3_21 = 0;
		SCL_3_3 = 0;
		totNum = 0;
		for(i = 1; i < N_MAX_PHASE; i++){
			retCnd = FileRead(&filePhas, i, 1, &phas, sizeof(phas_struc));
			if(retCnd != R_NORMAL){
				delete excelObj;
				excelObj = NULL;
				return(RT_FAILED);
			}
			
			if(phas.phase == 0)
				continue;
			
			if(phas.tecCycIdx == 0)
				continue;

			GetZoneIdxVirtCoo(phas.SV_X, phas.SV_Y, &startZoneIdx);
			GetZoneIdxVirtCoo(phas.DV_X, phas.DV_Y, &destZoneIdx);
			
			retSt = GetObjtIdx(phas.obj_type, &objtIdx);
			retSt = GetObjIdx(phas.object, &objIdx);

			if(startZoneIdx == zoneReactIdx){
				//Arrivo in Z21//
				if(CheckSuperZone(destZoneIdx, zoneFAIdx) == RT_NORMAL){
					if(objtIdx == S_FAIdx)
						SFA_3_21++;
					else if(objtIdx == S_CLIdx)
						SCL_3_21++;
				}
				//Arrivo in Z23//
				else if(destZoneIdx == zoneFFDSIdx){
					if(objtIdx == S_FAIdx)
						SFA_3_23++;
				}
				//Arrivo in Z3//
				else if(destZoneIdx == zoneReactIdx){
					if(objtIdx == S_FAIdx)
						SFA_3_3++;
					else if(objtIdx == S_CLIdx)
						SCL_3_3++;
				}
			}
			else
				continue;

			if(phas.campNum == camp.seqNum){
				totNum++;
				if(phas.tecCycIdx != 0){
					retSt = GetTechCycId(phas.tecCycIdx, tcId);
					retSt = GetTechCycDescription(tcId, tcDescr);
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCID_RP, tcId);
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCDESCR_RP, tcDescr);
				}
				else{
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCID_RP, _T("N/A"));
					excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_TCDESCR_RP, phas.cmd_type);
				}
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_OBJE_RP, phas.object);
				GetObjtIdx(phas.obj_type, &genIdx);
				GetObjtDescription(genIdx, temp);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_OBJT_RP, temp);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_SVX_RP, phas.SV_X);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_SVY_RP, phas.SV_Y);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_DVX_RP, phas.DV_X);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_DVY_RP, phas.DV_Y);
				/*
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_PRAL_RP, phas.quoteTrans);
				excelObj->SetCellsValueDbl(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_CUAL_RP, phas.quoteInst);
				*/

				retCnd = ConvertFromApmsTimeEx (&phas.sta_phse_time, &year, &month, &day, &hour, &min, &sec, &msec);
				if(year != 1991)
					_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), day, month, year, hour, min, sec);
				else
					_stprintf_s(temp, _T("No time"));
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_STTI_RP, temp);
				retCnd = ConvertFromApmsTimeEx (&phas.end_phse_time, &year, &month, &day, &hour, &min, &sec, &msec);
				if(year != 1991)
					_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), day, month, year, hour, min, sec);
				else
					_stprintf_s(temp, _T("No time"));
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_ENTI_RP, temp);
				
				switch(phas.esito){
				case PHAS_TOEXECUTE:
					_stprintf_s(temp, _T("Still to execute"));
					break;
				case PHAS_EXECUTED:
					_stprintf_s(temp, _T("Exexuted"));
					break;
				case PHAS_FAILED:
					_stprintf_s(temp, _T("Failed"));
					break;
				case PHAS_PLANNED:
					_stprintf_s(temp, _T("Planned"));
					break;
				case PHAS_INTERRUPTED:
					_stprintf_s(temp, _T("Interrupted"));
					break;
				case PHAS_INEXECUTION:
					_stprintf_s(temp, _T("In progress"));
					break;
				case PHAS_SUSPENDED:
					_stprintf_s(temp, _T("Suspended"));
					break;
				default:
					_stprintf_s(temp, _T("Unknown status"));
					break;
				}
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_STATUS_RP, temp);
				GetUserNameFromIdx(phas.startCondUserIdx, phUserName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_OPERATOR_SP, phUserName);
				GetUserNameFromIdx(phas.phConf.userIdx, phUserName);
				excelObj->SetCellsValueStr(XLS_ROW_DATA_INIT_RP + totNum - 1, XLS_COL_SUPVIS_SP, phUserName);
			}	
		}

		//Compilo i campi con i dati del documento e con i contatori.//
		excelObj->SetCellsValueStr(XLS_ROW_DOC_NAME_RP, XLS_COL_DATA, fileName);
		_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_DATE_RP, XLS_COL_DATA, temp);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_TYPE_RP, XLS_COL_DATA, _T("New Fuel Storage (Area 1) Report"));
		_stprintf_s(temp, _T("Refuelling Campaign N� %d, year %d"), camp.seqNum, camp.year);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_CAMP_RP, XLS_COL_DATA, temp);
		excelObj->SetCellsValueDbl(XLS_ROW_DOC_TOTC_RP, XLS_COL_DATA, totNum);
		excelObj->SetCellsValueStr(XLS_ROW_DOC_USER_RP, XLS_COL_DATA, userName);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT, XLS_COL_TECCYC_DESCR, _T("Spent FA displaced from Reactor (Z3) to FFDS zone (Z23)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT, XLS_COL_TECCYC_NUM, SFA_3_23);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 1, XLS_COL_TECCYC_DESCR, _T("Spent FA displaced from Reactor (Z3) to Reactor (Z3)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 1, XLS_COL_TECCYC_NUM, SFA_3_3);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 2, XLS_COL_TECCYC_DESCR, _T("Spent FA displaced from Reactor (Z3) to Spent Fuel Pool (Z21)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 2, XLS_COL_TECCYC_NUM, SFA_3_21);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 3, XLS_COL_TECCYC_DESCR, _T("Spent Clusters displaced from Reactor (Z3) to Reactor (Z3)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 3, XLS_COL_TECCYC_NUM, SCL_3_3);
		excelObj->SetCellsValueStr(XLS_ROW_TECCYC_NUM_FRT + 4, XLS_COL_TECCYC_DESCR, _T("Spent Clusters displaced from Reactor (Z3) to Spent Fuel Pool (Z21)"));
		excelObj->SetCellsValueDbl(XLS_ROW_TECCYC_NUM_FRT + 4, XLS_COL_TECCYC_NUM, SCL_3_21);
		
		retI = excelObj->SaveWorkBook(fileName);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->CloseActiveWorkBook(false);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->Close();
		delete excelObj;
		excelObj = NULL;
		
		retB = SetFileAttributes(fileName, FILE_ATTRIBUTE_READONLY);
		if(retB == 0)
			return(RT_FAILED);

		break;
	
	case REP_FALV:
		excelObj = new CXlsObj;
		retI = excelObj->Init();
		if(!retI){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
	
		retI = excelObj->OpenWorkBook(templateFALVPath, VARIANT_FALSE, 1);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		falvChecked = 0;
		noOpt = false;
		devs = false;

		_stprintf_s(fileName, defaultFileNameFALV, sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute);
		
		for(i = 1; i <= N_MAX_FALV; i++){
			retSt = GetFalv(i, &falv);
			if(retSt != RT_NORMAL){
				delete excelObj;
				excelObj = NULL;
				return(RT_FAILED);
			}
			
			if((falv.virtX == 0) && (falv.virtY == 0))
				continue;
			
			falvChecked++;
			full = false;
			
			excelObj->SetCellsValueDbl(XLS_FALV_ROW_DATA_INIT + falvChecked - 1, XLS_FALV_COL_VIRT_X, falv.virtX);
			excelObj->SetCellsValueDbl(XLS_FALV_ROW_DATA_INIT + falvChecked - 1, XLS_FALV_COL_VIRT_Y, falv.virtY);
			_stprintf_s(temp, _T("%.1f"), falv.qouteResult);
			excelObj->SetCellsValueStr(XLS_FALV_ROW_DATA_INIT + falvChecked - 1, XLS_FALV_COL_QUOTE, temp);

			if(falv.cellSituation.obj[OBJT_N_CLUS] != 0)
				full = true;
			
			if(falv.cellSituation.obj[OBJT_N_FA] == 0){
				delete excelObj;
				excelObj = NULL;
				return(RT_FAILED);
			}

			retSt = GetObjName(falv.cellSituation.o_id[OBJT_N_FA], objName);
			if(retSt != RT_NORMAL){
				delete excelObj;
				excelObj = NULL;
				return(RT_FAILED);
			}	

			retSt = GetObjtName(falv.cellSituation.obj[OBJT_N_FA], objtName);
			if(retSt != RT_NORMAL){
				delete excelObj;
				excelObj = NULL;
				return(RT_FAILED);
			}

			if(full){
				if(devs == false){
					devs = true;
					campNum = falv.campSeqNum;
					campYear = falv.campYear;
				}

				retSt = GetObjName(falv.cellSituation.o_id[OBJT_N_CLUS], objName_1);
				if(retSt != RT_NORMAL){
					delete excelObj;
					excelObj = NULL;
					return(RT_FAILED);
				}	

				_stprintf_s(temp, _T("%s, %s"), objName, objName_1);
				excelObj->SetCellsValueStr(XLS_FALV_ROW_DATA_INIT + falvChecked - 1, XLS_FALV_COL_OBJ, temp);

				retSt = GetObjtName(falv.cellSituation.obj[OBJT_N_CLUS], objtName_1);
				if(retSt != RT_NORMAL){
					delete excelObj;
					excelObj = NULL;
					return(RT_FAILED);
				}

				_stprintf_s(temp, _T("%s, %s"), objtName, objtName_1);
				excelObj->SetCellsValueStr(XLS_FALV_ROW_DATA_INIT + falvChecked - 1, XLS_FALV_COL_OBJT, temp);

			}
			else{
				excelObj->SetCellsValueStr(XLS_FALV_ROW_DATA_INIT + falvChecked - 1, XLS_FALV_COL_OBJ, objName);
				excelObj->SetCellsValueStr(XLS_FALV_ROW_DATA_INIT + falvChecked - 1, XLS_FALV_COL_OBJT, objtName);
			}
			
			retCnd = ConvertFromApmsTimeEx (&falv.checkTime, &year, &month, &day, &hour, &min, &sec, &msec);
			if(year != 1991)
				_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), day, month, year, hour, min, sec);
			else
				_stprintf_s(temp, _T("No time"));
			
			excelObj->SetCellsValueStr(XLS_FALV_ROW_DATA_INIT + falvChecked - 1, XLS_FALV_COL_DATE, temp);
		}

		//Compilo i dati di intestazione del documento.//
		excelObj->SetCellsValueStr(XLS_FALV_ROW_DOC_NAME, XLS_FALV_COL_DOC_NAME, fileName);
		_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
		excelObj->SetCellsValueStr(XLS_FALV_ROW_DOC_DATE, XLS_FALV_COL_DOC_DATE, temp);
		excelObj->SetCellsValueStr(XLS_FALV_ROW_DOC_TYPE, XLS_FALV_COL_DOC_TYPE, _T("FA installation quote check results report"));
		_stprintf_s(temp, _T("Refuelling Campaign N� %d, year %d"), campNum, campYear);
		excelObj->SetCellsValueStr(XLS_FALV_ROW_DOC_CAMP, XLS_FALV_COL_DOC_CAMP, temp);
		excelObj->SetCellsValueStr(XLS_FALV_ROW_DOC_USER, XLS_FALV_COL_DOC_USER, userName);
		
		retSt = GetZoneCellNum(zoneReactIdx, &totNum);
		if(retSt != RT_NORMAL){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		excelObj->SetCellsValueDbl(XLS_FALV_ROW_TOTCELL, XLS_FALV_COL_INFO, totNum);
		excelObj->SetCellsValueDbl(XLS_FALV_ROW_CHKCELL, XLS_FALV_COL_INFO, falvChecked);
	
		retI = excelObj->SaveWorkBook(fileName);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		retI = excelObj->CloseActiveWorkBook(false);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->Close();
		delete excelObj;
		excelObj = NULL;
		
		retB = SetFileAttributes(fileName, FILE_ATTRIBUTE_READONLY);
		if(retB == 0)
			return(RT_FAILED);

		break;

	case REP_DMP:
		excelObj = new CXlsObj;
		retI = excelObj->Init();
		if(!retI){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		retI = excelObj->OpenWorkBook(templateDMPPath, VARIANT_FALSE, 1);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		dmpChecked = 0;
		noOpt = false;
		devs = false;

		_stprintf_s(fileName, defaultFileNameDMP, sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute);
		
		for(i = 1; i <= N_MAX_DMP; i++){
			retSt = GetDMP(i, &dmp);
			if(retSt != RT_NORMAL){
				delete excelObj;
				excelObj = NULL;
				return(RT_FAILED);
			}
			
			if((dmp.virtX == 0) && (dmp.virtY == 0))
				continue;
			
			dmpChecked++;
			

			excelObj->SetCellsValueDbl(XLS_DMP_ROW_DATA_INIT + dmpChecked - 1, XLS_DMP_COL_VIRT_X, dmp.virtX);
			excelObj->SetCellsValueDbl(XLS_DMP_ROW_DATA_INIT + dmpChecked - 1, XLS_DMP_COL_VIRT_Y, dmp.virtY);
			excelObj->SetCellsValueDbl(XLS_DMP_ROW_DATA_INIT + dmpChecked - 1, XLS_DMP_COL_QUOTE, dmp.qouteResult);

			retCnd = ConvertFromApmsTimeEx (&dmp.checkTime, &year, &month, &day, &hour, &min, &sec, &msec);
			if(year != 1991)
				_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), day, month, year, hour, min, sec);
			else
				_stprintf_s(temp, _T("No time"));
			
			excelObj->SetCellsValueStr(XLS_DMP_ROW_DATA_INIT + dmpChecked - 1, XLS_DMP_COL_DATE, temp);
		}

		//Compilo i dati di intestazione del documento.//
		excelObj->SetCellsValueStr(XLS_DMP_ROW_DOC_NAME, XLS_DMP_COL_DOC_NAME, fileName);
		_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
		excelObj->SetCellsValueStr(XLS_DMP_ROW_DOC_DATE, XLS_DMP_COL_DOC_DATE, temp);
		excelObj->SetCellsValueStr(XLS_DMP_ROW_DOC_TYPE, XLS_DMP_COL_DOC_TYPE, _T("FA mounting places inspection results report"));
		_stprintf_s(temp, _T("Refuelling Campaign N� %d, year %d"), camp.seqNum, camp.year);
		excelObj->SetCellsValueStr(XLS_DMP_ROW_DOC_CAMP, XLS_DMP_COL_DOC_CAMP, temp);
		excelObj->SetCellsValueStr(XLS_DMP_ROW_DOC_USER, XLS_DMP_COL_DOC_USER, userName);
		
		retSt = GetZoneCellNum(zoneReactIdx, &totNum);
		if(retSt != RT_NORMAL){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		excelObj->SetCellsValueDbl(XLS_DMP_ROW_TOTCELL, XLS_DMP_COL_INFO, totNum);
		excelObj->SetCellsValueDbl(XLS_DMP_ROW_CHKCELL, XLS_DMP_COL_INFO, dmpChecked);
	
		retI = excelObj->SaveWorkBook(fileName);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		retI = excelObj->CloseActiveWorkBook(false);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->Close();
		delete excelObj;
		excelObj = NULL;
		
		retB = SetFileAttributes(fileName, FILE_ATTRIBUTE_READONLY);
		if(retB == 0)
			return(RT_FAILED);

		break;

	case REP_MOV:
		excelObj = new CXlsObj;
		retI = excelObj->Init();
		if(!retI){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->OpenWorkBook(templateMOVPath, VARIANT_FALSE, 1);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		noOpt = false;
		devs = false;
		retSt = GetMicroCmdIdx(MICRO_MOVE_FAGRL_MM, &FAGRLIdx);
		retSt = GetMicroCmdIdx(MICRO_DISP_MM, &displIdx);
		_stprintf_s(fileName, defaultFileNameMOV, sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute);
		
		for(i = 1; i <= N_MAX_RPMB; i++){
			retSt = GetRPMB(i, &rpmb);
			if(retSt != RT_NORMAL)
				return(RT_FAILED);
			if(rpmb.movType == 0)
				break;
			

			excelObj->SetCellsValueDbl(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_NUM, (double)(i));
			retSt = GetMicrDescrFromIdx(rpmb.movType, micrDescr);
			excelObj->SetCellsValueStr(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_MOV, micrDescr);
			if(rpmb.movType == FAGRLIdx){
				if(rpmb.setPoint == SP_OPEN)
					excelObj->SetCellsValueStr(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_SP, _T("OPEN"));
				else
					excelObj->SetCellsValueStr(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_SP, _T("CLOSE"));
				
				if(rpmb.startPos == SP_OPEN)
					excelObj->SetCellsValueStr(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_START_POS, _T("OPEN"));
				else
					excelObj->SetCellsValueStr(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_START_POS, _T("CLOSE"));
			}
			else if(rpmb.movType == FAGRLIdx){
				if(rpmb.setPoint == 0)
					excelObj->SetCellsValueStr(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_SP, _T("LOW"));
				else
					excelObj->SetCellsValueStr(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_SP, _T("RAISE"));
				
				if(rpmb.startPos == 0)
					excelObj->SetCellsValueStr(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_START_POS, _T("LOW"));
				else
					excelObj->SetCellsValueStr(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_START_POS, _T("RAISE"));
			}
			else{
				excelObj->SetCellsValueDbl(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_SP, (double)(rpmb.setPoint));
				excelObj->SetCellsValueDbl(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_START_POS, (double)(rpmb.startPos));
			}
			switch(rpmb.result){
			case RPMB_OP_OK:
				_stprintf_s(temp, _T("Completed"));
				break;
			case RPMB_OP_NOOK:
				_stprintf_s(temp, _T("Failed"));
				break;
			case RPMB_OP_STOPPED:
				_stprintf_s(temp, _T("Stopped"));
				break;
			default:
				_stprintf_s(temp, _T("Unknown"));
				break;
			}
			excelObj->SetCellsValueStr(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_RES, temp);
			retCnd = ConvertFromApmsTimeEx (&rpmb.startTime, &year, &month, &day, &hour, &min, &sec, &msec);
			if(year != 1991)
				_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
			else
				_stprintf_s(temp, _T("No time"));
			excelObj->SetCellsValueStr(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_START_TIME, temp);
			retCnd = ConvertFromApmsTimeEx (&rpmb.endTime, &year, &month, &day, &hour, &min, &sec, &msec);
			if(year != 1991)
				_stprintf_s(temp, _T("[%2d/%2d/%2d - %2d:%2d.%2d]"), day, month, year, hour, min, sec);
			else
				_stprintf_s(temp, _T("No time"));
			excelObj->SetCellsValueStr(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_END_TIME, temp);
			retSt = GetUserNameFromIdx(rpmb.opIdx, phUserName);						
			excelObj->SetCellsValueStr(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_OPERATOR, phUserName);
			switch(rpmb.opMode){
			case M_AUTOMATIC:
				_stprintf_s(temp, _T("Automatic"));
				break;
			case M_SEMIAUTO:
				_stprintf_s(temp, _T("Semiautomatic"));
				break;
			case M_PROTECT:
				_stprintf_s(temp, _T("Manual protected"));
				break;
			case M_EMERGEN:
				_stprintf_s(temp, _T("Emergency"));
				break;
			case M_MAN_SINGLE_CH:
				_stprintf_s(temp, _T("Manual Single Channel"));
				break;
			case M_MAN_WO_INT:
				_stprintf_s(temp, _T("Manual without Interlocks"));
				break;
			default:
				_stprintf_s(temp, _T("Unknown mode"));
				break;
			}
			excelObj->SetCellsValueStr(XLS_MOV_ROW_DATA_INIT + i - 1, XLS_MOV_COL_OP_MODE, temp);
		}
		//Compilo i dati di intestazione del documento.//
		excelObj->SetCellsValueStr(XLS_MOV_ROW_DOC_NAME, XLS_MOV_COL_DOC_NAME, fileName);
		_stprintf_s(temp, _T("[%02d/%02d/%2d - %02d:%02d.%02d]"), sysTime.wDay, sysTime.wMonth, sysTime.wYear, sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
		excelObj->SetCellsValueStr(XLS_MOV_ROW_DOC_DATE, XLS_MOV_COL_DOC_DATE, temp);
		retSt = GetCamp(&camp);
		_stprintf_s(temp, _T("Refuelling Campaign N� %d, year %d"), camp.seqNum, camp.year);
		excelObj->SetCellsValueStr(XLS_MOV_ROW_DOC_CAMP, XLS_MOV_COL_DOC_CAMP, temp);
		excelObj->SetCellsValueStr(XLS_MOV_ROW_DOC_USER, XLS_MOV_COL_DOC_USER, userName);
		
		
		retI = excelObj->SaveWorkBook(fileName);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		retI = excelObj->CloseActiveWorkBook(false);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->Close();
		delete excelObj;
		excelObj = NULL;

		break;
	case REP_FA_HIST:
		excelObj = new CXlsObj;
		retI = excelObj->Init();
		if(!retI){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}

		retI = excelObj->OpenWorkBook(templateFAPath, VARIANT_FALSE, 1);
		if(retI == 0){
			delete excelObj;
			excelObj = NULL;
			return(RT_FAILED);
		}
		
		break;
	default:
		goto END_ERROR;
	}
	
	return(RT_NORMAL);
END_ERROR:
	return(RT_FAILED);
}


RETSTAT BuildReportEx(bool reportType[N_MAX_REP], TCHAR userName[SZUNAM+1]){
	RETSTAT		retSt;
	int			i;

	for(i = 0; i < N_MAX_REP; i++){
		if(reportType[i]){
			retSt = BuildReport(i + 1, userName);
			if(retSt != RT_NORMAL)
				return(retSt);
		}
	}
	return(RT_NORMAL);
}

void GetFileNameFromPath(TCHAR *path, TCHAR filename[32]){
	int		len;
	int		i;
	int		pos;

	len = _tcslen(path);
	
	for(i = 0; i < len ; i++){
		if(path[i] == '\\')
			pos = i + 1;
	}
	
	
	for(i = pos; i < len; i++)
		filename[i - pos] = path[i];
}

/********************************************************************************************/
/*																							*/
/*	Function:		CheckReportFeasibility													*/
/*	Description:	Check wether a report type has any entry in current campaign			*/
/*	Input:			reportType		-	Type of record to check								*/
/*										1)	REP_PSAS_FA										*/
/*										2)	REP_PSAS_HECA									*/
/*										3)	REP_PSAS_REACT									*/
/*										4)	REP_RP_LOAD										*/
/*										5)	REP_RP_UNLOAD									*/
/*										6)	REP_RP_SFP										*/
/*										7)	REP_RP_REACT									*/
/*										8)  REP_MOV											*/
/*										9)	REP_FA_HIST										*/
/*										10)	REP_FALV										*/
/*										11)	REP_DMP											*/
/*	Output:			flag			-	Report feasibility flag								*/
/*	Return:			RETSTAT			-	RT_NORMAL		Succesful report check				*/
/*										RT_FAILED		Erorrs occurred						*/
/*																							*/
/********************************************************************************************/
RETSTAT CheckReportFeasibility(int reportType, int *flag){
	RETSTAT		retSt;
	GENIDX		zoneSfpIdx;
	GENIDX		zoneReactIdx;
	GENIDX		zoneIOIdx;
	GENIDX		startZoneIdx;
	GENIDX		destZoneIdx;
	t_camp		camp;
	int			falvFlag;
	int			dmpFlag;
	int			rec;
	phas_struc	phas;
	bool		repFound;

	retSt = GetZoneIdx(ZONE_REACTOR, &zoneReactIdx);
	retSt = GetZoneIdx(ZONE_IO, &zoneIOIdx);
	retSt = GetZoneIdx(ZONE_MAIN, &zoneSfpIdx);
	
	*flag = 0;

	switch(reportType){
	case REP_PSAS_FA:
	case REP_PSAS_HECA:
	case REP_PSAS_REACT:
	case REP_MOV:
	case REP_FA_HIST:
		*flag = 1;
		return(RT_NORMAL);
		break;
	case REP_FALV:
		falvFlag = 0;
		retSt = GetCamp(&camp);
		if(retSt != RT_NORMAL)
			return(retSt);
		retSt = FALVinCamp(camp.seqNum, camp.year, &falvFlag);
		if(retSt != RT_NORMAL)
			return(retSt);
		*flag = falvFlag;
		return(RT_NORMAL);
		break;
	case REP_DMP:
		dmpFlag = 0;
		retSt = GetCamp(&camp);
		if(retSt != RT_NORMAL)
			return(retSt);
		retSt = DMPinCamp(camp.seqNum, camp.year, &dmpFlag);
		if(retSt != RT_NORMAL)
			return(retSt);
		*flag = dmpFlag;
		return(RT_NORMAL);
		break;
	case REP_RP_LOAD:
		repFound = false;
		for(rec = 1; rec <= N_MAX_PHASE; rec++){
			retSt = GetPhase(rec, &phas);
			if(retSt == RT_FAILED)
				return(retSt);
			else if(retSt == RT_INVPHAS)
				break;

			if(phas.phase == 0)
				break;

			if(phas.tecCycIdx == 0)
				continue;

			if((phas.SV_X == 0) || (phas.SV_Y == 0) || (phas.DV_X == 0) || (phas.DV_Y == 0))
				continue;

			retSt = GetZoneIdxVirtCoo(phas.SV_X, phas.SV_Y, &startZoneIdx);
			if(retSt != RT_NORMAL)
				return(retSt);

			if(startZoneIdx == zoneIOIdx){
				repFound = true;
				break;
			}
		}
		if(repFound)
			*flag = 1;
		else
			*flag = 0;
		return(RT_NORMAL);
		break;
	case REP_RP_UNLOAD:
		repFound = false;
		for(rec = 1; rec <= N_MAX_PHASE; rec++){
			retSt = GetPhase(rec, &phas);
			if(retSt == RT_FAILED)
				return(retSt);
			else if(retSt == RT_INVPHAS)
				break;

			if(phas.phase == 0)
				break;

			if(phas.tecCycIdx == 0)
				continue;

			if((phas.SV_X == 0) || (phas.SV_Y == 0) || (phas.DV_X == 0) || (phas.DV_Y == 0))
				continue;

			retSt = GetZoneIdxVirtCoo(phas.DV_X, phas.DV_Y, &destZoneIdx);
			if(retSt != RT_NORMAL)
				return(retSt);

			if(destZoneIdx == zoneIOIdx){
				repFound = true;
				break;
			}
		}
		if(repFound)
			*flag = 1;
		else
			*flag = 0;
		return(RT_NORMAL);
		break;
	case REP_RP_REACT:
		repFound = false;
		for(rec = 1; rec <= N_MAX_PHASE; rec++){
			retSt = GetPhase(rec, &phas);
			if(retSt == RT_FAILED)
				return(retSt);
			else if(retSt == RT_INVPHAS)
				break;

			if(phas.phase == 0)
				break;

			if(phas.tecCycIdx == 0)
				continue;

			if((phas.SV_X == 0) || (phas.SV_Y == 0) || (phas.DV_X == 0) || (phas.DV_Y == 0))
				continue;

			retSt = GetZoneIdxVirtCoo(phas.SV_X, phas.SV_Y, &startZoneIdx);
			if(retSt != RT_NORMAL)
				return(retSt);

			if(startZoneIdx == zoneReactIdx){
				repFound = true;
				break;
			}
		}
		if(repFound)
			*flag = 1;
		else
			*flag = 0;
		return(RT_NORMAL);
		break;
	case REP_RP_SFP:
		repFound = false;
		for(rec = 1; rec <= N_MAX_PHASE; rec++){
			retSt = GetPhase(rec, &phas);
			if(retSt == RT_FAILED)
				return(retSt);
			else if(retSt == RT_INVPHAS)
				break;

			if(phas.phase == 0)
				break;

			if(phas.tecCycIdx == 0)
				continue;
			
			if((phas.SV_X == 0) || (phas.SV_Y == 0) || (phas.DV_X == 0) || (phas.DV_Y == 0))
				continue;

			retSt = GetZoneIdxVirtCoo(phas.SV_X, phas.SV_Y, &startZoneIdx);
			if(retSt != RT_NORMAL)
				return(retSt);

			retSt = GetZoneIdxVirtCoo(phas.DV_X, phas.DV_Y, &destZoneIdx);
			if(retSt != RT_NORMAL)
				return(retSt);
			
			if((CheckSuperZone(startZoneIdx, zoneSfpIdx) == RT_NORMAL) && (destZoneIdx != zoneIOIdx)){
				repFound = true;
				break;
			}
		}
		if(repFound)
			*flag = 1;
		else
			*flag = 0;
		return(RT_NORMAL);
		break;
	default:
		return(RT_FAILED);
	}
	
	return(RT_FAILED);
}
